package com.jzy.bxb.app.server;

import java.io.File;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.jzy.bxb.app.manager.MongoManager;
import com.jzy.bxb.app.manager.RedisManager;
import com.jzy.bxb.core.script.ScriptManager;

/**
 * 启动类
 *
 * @author JiangZhiYong
 * @date 2017-06-20 QQ:359135103
 */
public class App {
	private static final Logger LOGGER = LoggerFactory.getLogger(App.class);

	private static String configPath;

	public static RedisManager redisManager;

	public static void main(String[] args) {
		initConfigPath();

		LOGGER.debug("加载脚本");
		ScriptManager.getInstance().init(str ->{
			LOGGER.warn(str);
			System.exit(1);
		});

		LOGGER.debug("连接redis");
		redisManager = new RedisManager(configPath);

		LOGGER.debug("连接mongo");
		MongoManager.getInstance().createConnect(configPath);

		LOGGER.debug("启动HTTP");
		AppHttpServer appHttpServer = new AppHttpServer(configPath);
		new Thread(appHttpServer).start();

		LOGGER.debug("=====启动APP成功=====");
	}

	private static void initConfigPath() {
		File file = new File(System.getProperty("user.dir"));
		if ("target".equals(file.getName())) {
			configPath = file.getPath() + File.separatorChar + "config";
		} else {
			configPath = file.getPath() + File.separatorChar + "target" + File.separatorChar + "config";
		}
		LOGGER.info("配置路径为：" + configPath);
	}
}
